<template>
    <div class="container">
        <h3>审核管理</h3>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <!-- <el-tab-pane label="提取饮片" name="1">
                <el-row>
                    <el-col :span="7">
                        <el-input style="border-radius: 0 5px 5px 0" placeholder="请输入关键词" v-model="searchName1">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch1">搜索</el-button>
                        </el-input>
                    </el-col>
                </el-row>
                    
                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                >
                    <el-table-column prop="breedName" sortable label="品名"></el-table-column>
                    <el-table-column prop="printNum" sortable label="分包数量"></el-table-column>
                    <el-table-column prop="weight" sortable label="每包装量">
                        <template slot-scope="scope">
                            {{scope.row.weight}}{{scope.row.printSpec}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="inventoryCode" sortable label="存货代码"></el-table-column>
                    <el-table-column prop="type" sortable label="状态">
                        <template slot-scope="scope">
                            {{scope.row.type == 0?'未审核' : scope.row.type == 1?'已通过':'已拒绝'}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                            <el-button type="text" v-if="scope.row.type == 0">
                                <el-dropdown style="color: #409EFF; font-size:12px">
                                    <span class="el-dropdown-link">
                                        审核
                                    </span>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item>
                                            <el-button
                                                type="text"
                                                @click="handleOk(scope.$index, scope.row)"
                                            >通过</el-button>
                                        </el-dropdown-item>
                                        <el-dropdown-item>
                                            <el-button
                                                type="text"
                                                @click="handleNo(scope.$index, scope.row)"
                                                style="color: red"
                                            >拒绝</el-button>
                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize1" @current-change="handleCurrentChange1" :total="total1" :current-page.sync="currentPage1" style="margin-top:20px"></el-pagination>
            </el-tab-pane> -->
            <el-tab-pane label="配方颗粒" name="1">
                <el-row style="margin: 10px 0 20px 0">
                    <el-col :span="7">
                        <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName2">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch2">搜索</el-button>
                        </el-input>
                    </el-col>
                </el-row>
                    
                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                >
					<el-table-column prop="inventoryType" sortable label="产品大类"></el-table-column>
                    <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                    <el-table-column prop="printNum" sortable label="分包数量">
                        <template slot-scope="scope">
                            {{scope.row.printNum}}包
                        </template>
                    </el-table-column>
                    <el-table-column prop="weight" sortable label="每包计量">
                        <template slot-scope="scope">
                            {{scope.row.weight}}{{scope.row.units}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="inventoryCode" sortable label="存货代码"></el-table-column>
					<el-table-column prop="time" sortable label="生产日期"></el-table-column>
					<el-table-column prop="deadLine" sortable label="有效期至"></el-table-column>
                    <el-table-column prop="type" sortable label="状态">
                        <template slot-scope="scope">
                            {{scope.row.type == 0?'未审核' : scope.row.type == 1?'已通过':'已拒绝'}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                            <span v-if="scope.row.isRecall == 0">
                            <el-button type="text" v-if="scope.row.type == 0" v-show="qx">
                                <el-dropdown style="color: #409EFF; font-size:12px">
                                    <span class="el-dropdown-link">
                                        审核
                                    </span>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item>
                                            <el-button
                                                type="text"
                                                @click="handleOk1(scope.$index, scope.row)"
                                            >通过</el-button>
                                        </el-dropdown-item>
                                        <el-dropdown-item>
                                            <el-button
                                                type="text"
                                                @click="handleNo1(scope.$index, scope.row)"
                                                style="color: red"
                                            >拒绝</el-button>
                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </el-button>
                            </span>
                            <el-button
                                v-if="scope.row.isRecall == 1"
                                type="info"
                                disabled
                            >已召回</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize2" @current-change="handleCurrentChange2" :total="total2" :current-page.sync="currentPage2" style="margin-top:20px"></el-pagination>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
import {print_findByList,print_isOk} from "@/request/api";
    export default {
        data() {
            return {
                searchName1: '',
                searchName2: '',
                activeName: '1',
                materialType: '配方颗粒',
                tableData: [],
                total1: 0,
                currentPage1:1,
                pagesize1:10,
                total2: 0,
                currentPage2:1,
                pagesize2:10,
                qx:true,
            };
        },
        created(){
            var data = JSON.stringify(this.$store.state.sh)
            var a = "审核"
            if(data.indexOf(a) != -1){
                this.qx = true
                // console.log(111)
            }else{
                this.qx = false
                // console.log(222)
            }
        },
        mounted(){
            this.init2()
            // console.log(this.$store.state.newStorge)
        },
        methods: {
            // 调用接口
            // init1(){
            //     print_findByList({
            //         materialType: '提取饮片',
            //         searchName: this.searchName1,
            //         page: this.currentPage1,
            //     }).then((res) =>{
            //         this.tableData = res.rows
            //         this.total1 = res.total
            //     })
            // },
            init2(){
                print_findByList({
                    materialType: '配方颗粒',
                    searchName: this.searchName2,
                    page: this.currentPage2,
                }).then((res) =>{
                    this.tableData = res.rows
                    this.total2 = res.total
                })
            },
            // tabs
            handleClick(tab, event) {
                this.materialType = tab.label
                // if (this.materialType == '提取饮片') {
                //     this.init1()
                // } else if(this.materialType == '配方颗粒') {
                //     this.init2()
                // }
            },
            // 查看
            handleView(index,row){
                this.$router.push({
                    path: '/examine/viewExamine',
                    query: { id: row.id }
                });
            },
            // 通过
            handleOk(index,row){
                this.$confirm('此操作将通过该条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    print_isOk({
                        id: row.id,
                        type: 1
                    }).then((res) =>{
                        // var index = this.ruleForm.list.indexOf(item)
                        // if (index !== -1) {
                        //     this.ruleForm.list.splice(index, 1)
                        // }
                        this.$notify({
                            title: '操作成功',
                            message: '通过成功',
                            type: 'success'
                        });
                        this.init1()
                    })
                });
            },
            // 拒绝
            handleNo(index,row){
                this.$confirm('此操作将拒绝该条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    print_isOk({
                        id: row.id,
                        type: 2
                    }).then((res) =>{
                        // var index = this.ruleForm.list.indexOf(item)
                        // if (index !== -1) {
                        //     this.ruleForm.list.splice(index, 1)
                        // }
                        this.$notify({
                            title: '操作成功',
                            message: '已拒绝',
                            type: 'success'
                        });
                        this.init1()
                    })
                });
            },
            // 通过
            handleOk1(index,row){
                this.$confirm('此操作将通过该条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    print_isOk({
                        id: row.id,
                        type: 1,
                    }).then((res) =>{
                        // var index = this.ruleForm.list.indexOf(item)
                        // if (index !== -1) {
                        //     this.ruleForm.list.splice(index, 1)
                        // }
                        this.$notify({
                            title: '操作成功',
                            message: '通过成功',
                            type: 'success'
                        });
                        this.init2()
                    })
                });
            },
            // 拒绝
            handleNo1(index,row){
                this.$confirm('此操作将拒绝该条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    print_isOk({
                        id: row.id,
                        type: 2
                    }).then((res) =>{
                       
                        this.$notify({
                            title: '操作成功',
                            message: '已拒绝',
                            type: 'success'
                        });
                        this.init2()
                    })
                });
            },
            // handleSearch1() {
            // },
            handleSearch2() {
                this.currentPage2 = 1
                this.init2()
            },
            // handleCurrentChange1(val){
            //     this.currentPage1 = val
            //     this.init1()
            // },
            handleCurrentChange2(val){
                this.currentPage2 = val
                this.init2()
            },
        }
    }
</script>

<style scoped>
.el-pagination{
    text-align: center;
}
.el-col{
    margin-bottom: 0;
}
.el-select .el-input {
width: 130px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.el-input--small .el-input__inner{
    border-radius: 5px 0 0 5px !important;
    border-right: none;
}
</style>